<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="cdnload" content="mockjs" />
    <title>js进度条</title>
    <style>
      #app .item_box {
        display: flex;
        padding: 4px;
        border-bottom: 1px solid #f1f1f1;
      }

      /* 进度条样式 */
      .read_pro {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 3px;
        background-color: #ddd;
      }
      .read_pro_inner {
        content: '';
        position: absolute;
        left: 0;
        height: 100%;
        background-color: #0089f2;
      }
    </style>
  </head>
  <body>
    <div class="read_pro">
      <div class="read_pro_inner"></div>
    </div>
    <script type="module" src="./171-main.js"></script>
    <script>
      const readProInner = document.querySelector('.read_pro_inner')
      // 进度条
      document.addEventListener('scroll', function (e) {
        const sh = document.documentElement.scrollHeight
        const ch = document.documentElement.clientHeight
        const st = document.documentElement.scrollTop || document.body.scrollTop
        readProInner.style.width = (st / (sh - ch)) * 100 + '%'
      })
    </script>
  </body>
</html>
